define(function(require, exports, module) {
	'use strict';
    var rk = require('rk');
    require('../../su/xsySuButtonBar/widget');

    $.widget('rk.xsyCustomizeButtonBar', $.rk.xsySuButtonBar, {
    	_create: function(){
            var me = this;
            var opt = me.options;
            var elem = me.element;

            me._super();
    	},


        _init : function(){
            var me = this;
            var opt = me.options;
            var elem = me.element;
            me._super();
        },


        transferCustomize : function(data){
            var me = this;
            var opt = me.options;
            var elem = me.element;

            data.url = "/json/crm_customize/transfer.action";
            data.postJson = {
                belongId : data.belongId,
                customizeIds : data.id
            }
            data.callback = function(json){
                var id = $.parseJSON(json.data);
                //这里和客户商机不同的原因是后端接口，自定义之前就这么返回数据的，不知道还有其他的哪个地方用到了，不敢改接口返回的数据结构
                if(id == data.id){
                    window.location.reload();
                } else{
                    window.location.href = '/customize.action?belongId=' + data.belongId;
                }   
            }
 
            me.transferEntity(data);
        },

        deleteCustomize : function(data){
            var id = data.id;
            var belongId = data.belongId;
            var name = data.name;
            var html = rk.i18n('ACCOUNT_DELETE_ARRAY_STRING_4',$.htmlEncode(name));
            $.postJson('/json/crm_customize/validate-delete.action?belongId=' + belongId, {
                customizeIds: id,
                belongId:belongId
            }).done(function(json) {
                if(json.status == 200001){
                    html = json.data;
                }
                $.confirm(html, function() {
                    $.postJson('/json/crm_customize/delete.action', {
                        customizeIds: id,
                        belongId:belongId
                    }).done(function(json) {
                        if (json.status == 0) {
                            setTimeout(function(){
                                window.location.href = '/customize.action?belongId=' + belongId;
                            }, 1000);
                            $.msg(rk.i18n('CRM_CORE_DELETE') + rk.i18n('CRM_CORE_SUCCESS'), 1);
                        } else {
                            $.msg(rk.i18n('CRM_CORE_DELETE') + rk.i18n('CRM_CORE_FAILED'));
                        }
                    }).fail(function(def, code, message) {
                        def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                    });
                });
            }).fail(function(def, code, message) {
                def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
            });
        },

        viewCustomizeLog : function(data){
            var me = this;
            var opt = me.options;
            var elem = me.element;

            data.postJson = {
                instanceId : data.id,
                belongId : data.belongId
            }
            data.url = '/json/crm_customize/entity-logs.action'
            me.viewEntityLog(data);
        }


    });
});